﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

public partial class web_pages_SanKetQuaPhongVan : System.Web.UI.Page
{
    public string masan;
    public string tensan;
    public string soVLT;
    public string soNTV;
    public string ma_vlt;
    public string ma_ntd;
    public string ma_ntv;
    public string ten_ntv;
    public string ten_vlt;
    public string ten_ntd;
    public Common comm = new Common();
    SanGDVL sanComm = new SanGDVL();
    public DataTable dtt_san;
    protected void Page_Load(object sender, EventArgs e)
    {
        masan = Request.QueryString["sid"];

        if (Session["SanNTD"] == null) Response.Redirect("SanDangNhap.aspx?sid=" + masan);
        if ((bool)Session["SanNTD"] == false) Response.Redirect("SanDangNhap.aspx?sid=" + masan);
       

        string sql = "SELECT * FROM sangiaodich "
                   + " inner join TrungTamViecLam on TrungTamViecLam.ma_trung_tam = sangiaodich.ma_trung_tam "
                   + " WHERE  ma_san =  " + masan; ;
        dtt_san = comm.getDataTable(sql);

        if (dtt_san.Rows.Count == 0)
        {

            Response.Redirect("SanNotFound.aspx");

        }
        else if (Convert.ToInt32(dtt_san.Rows[0]["kich_hoat"]) == 1)
        {

            tensan = "ĐANG MỞ";
            soVLT = sanComm.SoLuongVLT(masan);
            soNTV = sanComm.SoLuongNTV(masan);
            
            ma_ntv = Request.QueryString["mantv"];
            ma_vlt = Request.QueryString["mavlt"];

            txt_tenungvien.Text = new NguoiTimViecCommon().getTenNTV(ma_ntv);
            txt_tuyendung.Text = comm.getDataTable("select top 1 tieu_de_ho_so from ViecLamTrong_ho_so_tuyen_dung where ma_ho_so = " + ma_vlt).Rows[0][0].ToString();


            ma_ntd = new NhaTuyenDungCommon().getMaNTD(Session["SanNTDuser"].ToString());
            ten_ntd = NhaTuyenDungCommon.getTenDoanhNghiep(ma_ntd);
        }
     

    }
    public string mess = "";
    protected void Btn_dangky_Click(object sender, EventArgs e)
    {
     

            bool res = sanComm.NhapKetQuaTuyenDung(masan,ma_vlt,ma_ntv,ma_ntd,date1.SelectedDate.GetValueOrDefault().ToString("MM-dd-yyyy"),comm.TextFormat(txt_mota.Text), cbb_ketqua.SelectedValue);
            

       if(res)  
            mess = "<script type='text/javascript' > alert('Nhập Thông Tin Thành Công!'); window.location.href = 'SanNhaTuyenDung.aspx?sid="+masan+"'  </script>";
       else
            mess = "<script type='text/javascript' > alert('Không thể Nhập Thông Tin!'); </script>";
    }
   
}
